// 例子21

{
    console.log(1, ...[2, 3, 4], 5); // 1 2 3 4 5
}

console.log('----------------------------------');

{
    console.log([...document.querySelectorAll('div')]); // [<div>, <div>, <div>, ..., <div>]
}

console.log('----------------------------------');

{
    function add(x, y) {
		return x + y;
    }

    const numbers = [1, 2];
    console.log(add(...numbers)); // 3
}

console.log('----------------------------------');

{
    // 替换apply方法
    const numbers = [1, 10, 5, 0];
    // ES5写法
    console.log(Math.max.apply(null, numbers)); // 10

    // ES6语法
    console.log(Math.max(...numbers)); // 10
}

console.log('----------------------------------');

{
    {
        // 替换apply方法
        // ES5的写法
        var arr1 = [0, 1, 2];
        var arr2 = [3, 4, 5];
        Array.prototype.push.apply(arr1, arr2);
        console.log(arr1); // [0, 1, 2, 3, 4, 5]
    }

    {
        // ES6的写法
        let arr1 = [0, 1, 2];
        let arr2 = [3, 4, 5];
        arr1.push(...arr2);
        console.log(arr1); // [0, 1, 2, 3, 4, 5]
    }

}